package demo2;


import java.util.Arrays;

/**
 * @ClassDescription:
 * @JdkVersion: 1.8
 * @Author: 李白
 * @Created: 2024/5/17 16:41
 */
public class Test {
    public static void main(String[] args) {
        Student1[] students = new Student1[3];
        students[0] = new Student1("zhangsan", 19);
        students[1] = new Student1("lisi", 2);
        students[2] = new Student1("wangwu", 30);
        System.out.println("排序前: " + Arrays.toString(students));
    }
}
class Student1 implements Comparable<Student1>{
    public String name;
    public int age;

    public Student1(String name, int age) {
        this.name = name;
        this.age = age;
    }

 /*   @Override
    public int compareTo(Student o) {
        System.out.println("fffffffffffffffff");
        if (this.age > o.age){//this.age指的是调用compareTo的对象里的成员变量
            return 1;
        }else if(this.age == o.age){
            return 0;
        }else {
            return -1;
        }

    }*/

    @Override
    public int compareTo(Student1 o) {
        if (this.age > o.age){
            return 1;
        }else if (this.age == o.age){
            return 0;
        }else {
            return -1;
        }
    }
}
